
#include "semantics_simulation.h"
#include "generic_table.cpp"
#include "main_container.h"
#include "semantic_analyzer.h"
extern MainContainer * CompilerData;

SemanticsSimulation::SemanticsSimulation()
{
	this->CurrentContext=-1;
	this->Name = new GenericTable<int>();
	this->Body = new GenericTable<SemanticsSimulationStatement>;
}


SemanticsSimulation::~SemanticsSimulation()
{
	if(Name != NULL)
	{
		delete Name;
		Name = NULL;
	}

	if(Body != NULL)
	{
		delete Body;
		Body = NULL;
	}
}

#ifdef DEBUG
void SemanticsSimulationStatement::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimulationStatement type=\"");

	// write BlockType
	switch (*this->Type)
	{

	case SimStatConfiguration:
		fprintf(fo, "SimStatConfiguration");
		break;
	case SimStatRun:
		fprintf(fo, "SimStatRun");
		break;
	case SimStatClear:
		fprintf(fo, "SimStatClear");
		break;
	case SimStatReset:
		fprintf(fo, "SimStatReset");
		break;
	}
	fprintf(fo, "\"/>\n");
}
#endif

#ifdef DEBUG
void SemanticsSimStatConfiguration::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimStatConfiguration name=\"");

	// name inside starting tag
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->Name, CompilerData->Units);
	fprintf(fo, "\">\n");

	// call base 
	SemanticsSimulationStatement::DebugXMLOutput(fo);

	// make output of table Parameters
	fprintf(fo, "<parameters>\n");
	for(int i = 0; i < this->Parameters->GetCount(); i++)
	{
		SemanticsExpression * data = this->Parameters->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</parameters>\n");

	fprintf(fo, "</semanticsSimStatConfiguration>\n");
}
#endif

#ifdef DEBUG
void SemanticsSimStatRun::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimStatRun>\n");

	// call base 
	SemanticsSimulationStatement::DebugXMLOutput(fo);

	this->Expression->DebugXMLOutput(fo);
	this->UptoExpression->DebugXMLOutput("upToExpression", fo);

	fprintf(fo, "</semanticsSimStatRun>\n");
}
#endif


#ifdef DEBUG
void SemanticsSimStatClear::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimStatClear>\n");

	// call base 
	SemanticsSimulationStatement::DebugXMLOutput(fo);


	fprintf(fo, "</semanticsSimStatClear>\n");
}
#endif

#ifdef DEBUG
void SemanticsSimStatReset::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimStatClear>\n");

	// call base 
	SemanticsSimulationStatement::DebugXMLOutput(fo);


	fprintf(fo, "</semanticsSimStatClear>\n");
}
#endif

#ifdef DEBUG
void SemanticsSimulation::DebugXMLOutput(FILE * fo)
{
	fprintf(fo, "<semanticsSimulation currentContext=\"");
	fprintf(fo, "%d", this->CurrentContext);
	fprintf(fo, "\" name=\"");
	SemanticAnalyzer::DebugOutputNameFromTable(fo, this->Name, CompilerData->Units);
	fprintf(fo, "\">\n");


	// make output of table Body
	fprintf(fo, "<body>\n");
	for(int i = 0; i < this->Body->GetCount(); i++)
	{
		SemanticsSimulationStatement * data = this->Body->GetData(i);
		data->DebugXMLOutput(fo);
	}
	fprintf(fo, "</body>\n");

	fprintf(fo, "</semanticsSimulation>\n");

}
#endif